import 'question.dart';

class Quiz {
  //题库
  List<Question> _questions;
  //题目当前的位置
  int _currentQuestionIndex = -1;
  //得分
  int _score = 0;
  //打乱题库顺序
  Quiz(this._questions) {
    _questions.shuffle();
  }

  int get score => _score;
  int get currentQuestionIndex => _currentQuestionIndex;
  List<Question> get questions => _questions;
  int get questionLength => _questions.length;
  int get questionNum => _currentQuestionIndex + 1;

  get nextQuestion {
    _currentQuestionIndex++;
    print('_currentQuestionIndex: $_currentQuestionIndex');
    if (currentQuestionIndex >= questionLength) {
      return null;
    } else {
      return _questions[_currentQuestionIndex];
    }
  }

  void answer(bool isCorrect) {
    if (isCorrect) {
      _score++;
    }
  }
}
